import bb.cascades 1.0
import bb.data 1.0
import com.songs.data 1.0

ListView {
    id: songsVNList
    layout: StackListLayout {
        headerMode: ListHeaderMode.Sticky
    }
    // The data model used defined in the attachedObjects for the list.
    //dataModel: songsModel
    contextActions: [
    ActionSet {
        id: actionSet
        // put context menu actions here
        title: qsTr("Yêu thích")
        subtitle: qsTr("Thêm hoặc loại bỏ bài hát này trong danh sách bài yêu thích...")
        ActionItem {
            title:
            {
                if(selectedData.is_favorite==1) 
                {
                    qsTr("Không thích")
                }
                else
                {
                    qsTr("Thích")
                }    
            } 
            imageSource: 
            {
                if(selectedData.is_favorite==1) 
                {
                    "asset:///images/no-favorite.png"
                }
                else
                {
                    "asset:///images/favorite.png"
                }
            }
            onTriggered: {
                if(activeContextMenu)
                    toggleFavoriteSelectedSong();
            }
        }
    }
    ]
    // There are two types of item; header for alphabetic groups and standard items
    // showing the person name.
    listItemComponents: [
        ListItemComponent {
            type: "header"
                Header {
                    title: ListItemData
                }
        },
        ListItemComponent {
            type: "item"
            CustomItem{
                title: ListItemData.title
                lyrics: ListItemData.lyrics
                code: ListItemData.code
                selected: ListItem.selected
                imgFavorite: {
                    if(ListItemData.is_favorite==1)
                    {
                        "asset:///images/favorite.png"
                    }else
                    {
                        "asset:///images/no-favorite.png"
                    }
                }
            }
        }
    ]
    onTriggered: {
        // To avoid triggering navigation when pressing the header items, we check so that the
        // index path length is larger then one (one entry would be a group under a header item).
        if (indexPath.length > 1) {
            // Update the data that will be shown in the Quotes Page.
            selectedData = dataModel.data(indexPath);
            customdialog.currentItem = selectedData;
            customdialog.open();
        }
    }
    onActivationChanged: {
        if(active)
        {
            activeContextMenu = true;
            if (indexPath.length > 1)
            {
                selectedData = dataModel.data(indexPath);
                activeContextMenu = true;
            }
            //else 
        }
        
    }
    attachedObjects: [
        CustomDialogDetail {
            id: customdialog
            
        }// CustomDialogAlarm
    ]// attachedObjects
} // ListView